import os
def count_codelines(filename):  #定义统计行的函数

    all_line_num = 0              #总行数、
    empty_line_num = 0            #空行数、
    comment_line_num = 0          #注释行数
     with open("filename", 'r', encoding="utf-8") as fp:  #with语句读文件会自动调用close()方法，防止文件对象占用系统资源
         for line in fp:
             all_line_num += 1                 #统计所有的行数
             if line.strip() == "":
                 empty_line_num += 1           #统计空行数
             if line[0] == "#":
                 comment_line_num += 1         #统计注释行数
    return (all_line_num,empty_line_num,comment_line_num)

if __name__ == "__main__":
    codelines = count_codelines("input.txt")
    print("内容总行数:",codelines[1],
          "空行数:",codelines[2],
          "注释行数:",codelines[3])